/*     */ package com.qmsk.business.task.customerMessage.controller;
/*     */ 
/*     */ import com.qmsk.business.manage.user.dao.UserDAO;
/*     */ import com.qmsk.business.task.customerMessage.dao.CustomerMessageDao;
/*     */ import com.qmsk.business.weixin.customMenu.weiXinUtil.WeiXinUtil;
/*     */ import com.qmsk.business.weixin.infoMation.message.resp.Article;
/*     */ import com.utils.basic.ObjectComm;
/*     */ import com.utils.gson.in.GsonHeadOneRow;
/*     */ import com.utils.gson.in.ParserDataSetJson;
/*     */ import com.utils.gson.out.GsonEbRst;
/*     */ import com.utils.jdbc.connection.DbConnection;
/*     */ import com.utils.web.RequestUtils;
/*     */ import com.utils.web.ResponseUtils;
/*     */ import java.sql.SQLException;
/*     */ import java.util.ArrayList;
/*     */ import java.util.Date;
/*     */ import java.util.HashMap;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import org.apache.commons.lang.StringUtils;
/*     */ import org.apache.log4j.Logger;
/*     */ import org.springframework.beans.factory.annotation.Autowired;
/*     */ import org.springframework.stereotype.Controller;
/*     */ import org.springframework.transaction.annotation.Transactional;
/*     */ import org.springframework.web.bind.annotation.PathVariable;
/*     */ import org.springframework.web.bind.annotation.RequestMapping;
/*     */ 
/*     */ @Controller
/*     */ @RequestMapping({"/customerMessage"})
/*     */ public class CustomerMessageController
/*     */ {
/*  44 */   private static final Logger logger = Logger.getLogger(CustomerMessageController.class);
/*     */ 
/*     */   @Autowired
/*     */   private CustomerMessageDao dao;
/*     */ 
/*     */   @Autowired
/*     */   private UserDAO userDAO;
/*     */ 
/*     */   @RequestMapping(value={"find/customerMessage/{pageIdx}/{pageSize}"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*     */   public void getList(HttpServletRequest request, HttpServletResponse response, @PathVariable("pageIdx") Integer nPageIdx, @PathVariable("pageSize") Short nPageSize)
/*     */     throws Exception
/*     */   {
/*  75 */     nPageSize = RequestUtils.getRequestValidPageSize(nPageSize);
/*     */     try
/*     */     {
/*  78 */       Integer sendType = ObjectComm.objectToInteger(request.getParameter("sendType"));
/*  79 */       Map params = new HashMap();
/*  80 */       params.put("shopId", RequestUtils.getString(request, "shopId"));
/*  81 */       params.put("sendType", sendType);
/*  82 */       if (sendType.intValue() == 0) {
/*  83 */         params.put("memberOpenId", RequestUtils.getString(request, "openId"));
/*  84 */       } else if (sendType.intValue() == 1) {
/*  85 */         params.put("userOpenId", RequestUtils.getString(request, "openId"));
/*     */       } else {
/*  87 */         ResponseUtils.setErrorMsgResponse(RequestUtils.getReadJsonDataErrorMessage(request), response);
/*  88 */         return;
/*     */       }
/*     */ 
/*  91 */       GsonEbRst gsonEbRst = this.dao.getGsonOfParams(params, nPageIdx, 
/*  92 */         nPageSize);
/*  93 */       ResponseUtils.setResponseResult(gsonEbRst, response);
/*     */     } catch (SQLException e) {
/*  95 */       logger.error(e);
/*  96 */       ResponseUtils.setErrorMsgResponse(
/*  97 */         RequestUtils.getFindDataErrorMessage(request), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @RequestMapping(value={"find/messageCount"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*     */   public void messageCount(HttpServletRequest request, HttpServletResponse response) throws Exception
/*     */   {
/*     */     try {
/* 105 */       Long shopId = RequestUtils.getLong(request, "shopId");
/* 106 */       Long memberId = RequestUtils.getLong(request, "memberId");
/* 107 */       Integer fscount = this.dao.getUnlookCount(shopId, memberId, Integer.valueOf(0), Integer.valueOf(0));
/* 108 */       Integer sdcount = this.dao.getUnlookCount(shopId, memberId, Integer.valueOf(0), Integer.valueOf(1));
/* 109 */       String[] head = { "fscount", "sdcount" };
/* 110 */       Object[] data = { fscount, sdcount };
/* 111 */       ResponseUtils.toGsonEbRst(head, data, response);
/*     */     } catch (SQLException e) {
/* 113 */       logger.error(e);
/* 114 */       ResponseUtils.setErrorMsgResponse(
/* 115 */         RequestUtils.getFindDataErrorMessage(request), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @RequestMapping(value={"insert/insertInfo"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void insertInfo(HttpServletRequest request, HttpServletResponse response)
/*     */   {
/*     */     try
/*     */     {
/* 124 */       int nResult = 0;
/* 125 */       Long userId = Long.valueOf(0L);
/* 126 */       String title = null;
/* 127 */       String content = null;
/* 128 */       String sData = RequestUtils.getStringOfData(request);
/* 129 */       ParserDataSetJson p = ParserDataSetJson.fromString(sData);
/*     */       GsonHeadOneRow g;
/* 130 */       if ((p != null) && (p.isExistsInsertRows())) {
/* 131 */         g = (GsonHeadOneRow)p.getListInsertRows().get(0);
/* 132 */         g.addHeadData("createdTime", new Date());
/* 133 */         g.addHeadData("status", Integer.valueOf(0));
/* 134 */         g.addHeadData("sendType", Integer.valueOf(0));
/* 135 */         userId = ObjectComm.objectToLong(g.getValueOfName("userId"));
/* 136 */         title = ObjectComm.objectToString(g.getValueOfName("title"));
/* 137 */         content = ObjectComm.objectToString(g.getValueOfName("content"));
/* 138 */         nResult = this.dao.applyUpdates(p);
/*     */       }
/*     */       else {
/* 141 */         ResponseUtils.setErrorMsgResponse(
/* 142 */           RequestUtils.getReadDataErrorMessage(request), 
/* 143 */           response);
/* 144 */         return;
/*     */       }
/* 146 */       if (nResult > 0)
/*     */       {
/* 148 */         g = this.userDAO.selectUserById(userId);
/* 149 */         if (g != null) {
/* 150 */           String openId = (String)g.getValueOfName("openId");
/* 151 */           List news = new ArrayList();
/*     */ 
/* 153 */           Article article = new Article();
/* 154 */           article.setSendNewsTitle("消息互动");
/* 155 */           article.setSendNewsDescription(title + "\n" + content);
/* 156 */           article.setSendNewsPicUrl(null);
/* 157 */           article.setSendNewsUrl(null);
/* 158 */           news.add(article);
/* 159 */           if (StringUtils.isNotEmpty(openId)) {
/* 160 */             WeiXinUtil.sendNewsMessageOfMain(news, openId);
/*     */           }
/*     */         }
/*     */ 
/* 164 */         this.dao.commit();
/*     */       } else {
/* 166 */         this.dao.rollback();
/*     */       }
/* 168 */       ResponseUtils.setSqlResultResponse(nResult, 
/* 169 */         RequestUtils.getSqlInsertDataErrorMessage(request), 
/* 170 */         response);
/*     */     }
/*     */     catch (Exception e) {
/* 173 */       logger.error(e);
/* 174 */       ResponseUtils.setErrorMsgResponse(
/* 175 */         RequestUtils.getSqlInsertDataErrorMessage(request) + ":" + 
/* 176 */         e.getMessage(), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @Transactional(rollbackFor={Exception.class})
/*     */   @RequestMapping(value={"del"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void delete(HttpServletRequest request, HttpServletResponse response)
/*     */   {
/* 194 */     String id = RequestUtils.getStringOfId(request);
/*     */     try {
/* 196 */       String[] strParams = id.split(",");
/* 197 */       int nResult = this.dao.deleteParams(strParams);
/* 198 */       if (nResult > 0)
/* 199 */         DbConnection.commit();
/*     */       else {
/* 201 */         DbConnection.rollback();
/*     */       }
/* 203 */       ResponseUtils.setSqlResultResponse(nResult, 
/* 204 */         RequestUtils.getSqlDeleteDataErrorMessage(request), 
/* 205 */         response);
/*     */     } catch (Exception e) {
/* 207 */       DbConnection.rollback();
/* 208 */       logger.error(e);
/* 209 */       ResponseUtils.setErrorMsgResponse(
/* 210 */         RequestUtils.getSqlDeleteDataErrorMessage(request) + ":" + 
/* 211 */         e.getMessage(), response);
/*     */     }
/*     */   }
/*     */ }

/* Location:           C:\Users\Administrator\Desktop\新建文件夹\WEB-INF\classes\
 * Qualified Name:     com.qmsk.business.task.customerMessage.controller.CustomerMessageController
 * JD-Core Version:    0.5.3
 */